package lang

import (
	"blog/lang/zh"
	"fmt"
	"strings"
)

type lang struct {
	pool map[string]map[string]interface{}
}

func (a *lang) load() {
	var pool map[string]map[string]interface{} = make(map[string]map[string]interface{})
	pool["cn"] = zh.Cn
	a.pool = pool
}

func (a *lang) sw() map[string]interface{} {
	return a.pool["cn"]
}

func (a *lang) Get(key string) string {

	if !strings.Contains(key, ".") {
		for k, v := range a.sw() {
			if k == key {
				return v.(string)
			}
		}
	} else {
		keys := strings.Split(key, ".")
		for sk, sv := range a.sw() {
			fmt.Println(sk, keys[0])
			if sk == keys[0] {
				return sv.(map[string]string)[keys[1]]
			}
		}
	}

	return ""
}

var Lang = (func() *lang {
	l := &lang{}
	l.load()
	return l
})()
